package com.system.part.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.system.post.entity.Post;



@Entity
@Table(name="t_part")
public class Part {
	private Long partId;
	private String partName;
	private String duty;
	private Long employeeNum;
	private List<Post> posts = new ArrayList<Post>();//一对多岗位
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getPartId() {
		return partId;
	}
	public String getPartName(){
		return partName;
	}
	@JsonIgnore
	@OneToMany(mappedBy="part")
	public List<Post> getPosts() {
		return posts;
	}
	
	
	public String getDuty() {
		return duty;
	}
	
	public Long getEmployeeNum() {
		Long num=0L;
		for(Post post:posts) {
			num+=post.getActualNum();
		}
		employeeNum=num;
		return employeeNum;
	}

	public void setEmployeeNum(Long employeeNum) {
		this.employeeNum = employeeNum;
	}
	public void setDuty(String duty) {
		this.duty = duty;
	}
	public void setPartId(Long partId) {
		this.partId = partId;
	}
	public void setPartName(String partName) {
		this.partName = partName;
	}
	public void setPosts(List<Post> posts){
		this.posts = posts;
	}


	
	
}
